package cn.merryyou.jpa.domain.primarykey;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Embeddable;
import java.io.Serializable;

@Getter
@Setter
@ToString
@Embeddable
public class BookPublisherPK implements Serializable {

    private static final long serialVersionUID = -7988656089865012008L;

    private Integer book;
    private Integer publisher;

    public BookPublisherPK() {
    }

    @Override
    public int hashCode() {
        final int PRIME = 31;
        int result = 1;
        result = PRIME * result + ((book == null) ? 0 : book.hashCode());
        result = PRIME * result + ((publisher == null) ? 0 : publisher.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (null == obj) {
            return false;
        }
        final BookPublisherPK other = (BookPublisherPK) obj;
        if (book == null) {
            if (other.book != null) {
                return false;
            }
        } else if (!book.equals(other.book)) {
            return false;
        }
        if (publisher == null) {
            if (other.publisher != null) {
                return false;
            }
        } else if (!publisher.equals(other.publisher)) {
            return false;
        }
        return true;
    }

}
